/* $RCSFile: DBResourceProviderFactory.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/ADNCRM.ExternalResourceProvider/DBResourceProviderFactory.cs $
 * $log$
 * Revision 6 2010/08/06 19:56:30  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Web.Compilation;
using System.Web;
using System.Diagnostics;
using System.Globalization;
using ADNCRM.CustomResourceProviders;

namespace ADNCRM.CustomResourceProviders.DBResourceProvider
{

    public class DBResourceProviderFactory : ResourceProviderFactory
    {

        public override IResourceProvider CreateGlobalResourceProvider(string classKey)
        {
            if ( ResourceTraceSwitch.Sw.TraceVerbose )
                Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "[V]DBResourceProviderFactory CreateGlobalResourceProvider({0})", classKey),ResourceTraceSwitch.Sw.Info);
            return new DBResourceProvider(classKey); 
        }

        public override IResourceProvider CreateLocalResourceProvider(string virtualPath)
        {
            if ( ResourceTraceSwitch.Sw.TraceVerbose )
                Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "[V]DBResourceProviderFactory CreateLocalResourceProvider({0}", virtualPath),ResourceTraceSwitch.Sw.Info);

            // we should always get a path from the runtime
            string classKey     =   virtualPath;
            if (!string.IsNullOrEmpty(virtualPath))
            {
                virtualPath     =   virtualPath.Remove(0, 1);
                classKey        =   virtualPath.Remove(0, virtualPath.IndexOf('/') + 1);
            }

            return new DBResourceProvider(classKey);
        }
    }
}